package com.zhuss.product.processor;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.zhuss.bean.bo.product.hotLineSite.SearchHotLineSiteBo;
import com.zhuss.bean.vo.product.hotLineSite.ListHotLineSiteVo;
import com.zhuss.common.ListVo;
import com.zhuss.common.PageVo;
import com.zhuss.product.db.dao.ext.HotLineSiteDao;
import com.zhuss.product.db.entity.HotLineSite;
import com.zhuss.exception.DzcxException;
import com.zhuss.exception.ExceptionCode;


/**
 * @description: 热门线路站点读
 * @author: zhushanshuo
 * @create: Mon Jan 11 09:22:02 CST 2021
 **/
@Component("hotLineSiteRead")
public class HotLineSiteRead {
	
	@Autowired
	private HotLineSiteDao hotLineSiteDao;
	
	
	public Map<String, HotLineSite> listMap() {
		List<HotLineSite> list = hotLineSiteDao.listAll();
		Map<String, HotLineSite> map = new HashMap<>();
		for (HotLineSite c : list) {
			map.put(c.getHotLineId()+"", c);
		}
		return map;
	}
	
	/**
	 * 热门线路站点
	 * @return
	 */
	public Object listHotLineSite() {
		List<HotLineSite> hotLineSiteList = hotLineSiteDao.listAll();
		List<ListVo> result = new ArrayList<>();
		transferList(hotLineSiteList, result);
		return result;
	}
	
	
	/**
	 * 热门线路站点
	 * @return
	 */
	public Object listHotLineSite(List<Long> hotLineSiteIdList) {
		List<HotLineSite> result = hotLineSiteDao.listById(hotLineSiteIdList);
		return result;
	}
	
	
	/**
	 * 根据名字查询热门线路站点
	 * @param 
	 * @return
	 */
	public List<HotLineSite> list(String name) {
		List<HotLineSite> result = hotLineSiteDao.listByName(name);
		return result;
	}
	
	public List<HotLineSite> listNotId(String name, Long hotLineSiteId) {
		List<HotLineSite> result = new ArrayList<HotLineSite>();
		List<HotLineSite> list = list(name);
		for (HotLineSite c : list) {
			if (!c.getHotLineSiteId().equals(hotLineSiteId)) {
				result.add(c);
				break;
			}
		}
		return result;
	}
	
	/**
	 * 热门线路站点 
	 * @return
	 */
	public Object listHotLineSiteId() {
		List<HotLineSite> hotLineSiteList = hotLineSiteDao.listAll();
		List<Long> result = new ArrayList<>();
		transferListId(hotLineSiteList, result);
		return result;
	}
	
	private void transferListId(List<HotLineSite> hotLineSiteList, List<Long> result) {
		for (HotLineSite item : hotLineSiteList) {
			result.add(item.getHotLineSiteId());
		}
	}

	private void transferList(List<HotLineSite> hotLineSiteList, List<ListVo> result) {
		for (HotLineSite item : hotLineSiteList) {
			ListVo vo = new ListVo();
			vo.setKey(item.getHotLineSiteId());
			vo.setLabel(item.getHotLineId()+"");
			result.add(vo);
		}
		
	}

	/**
	 * 热门线路站点列表
	 * @param bo
	 * @return
	 */
	public Object list(SearchHotLineSiteBo bo) {
		PageVo<ListHotLineSiteVo> result = new PageVo<ListHotLineSiteVo>();
        result.setPageNum(bo.getPageNum());
        result.setPageSize(bo.getPageSize());
        result.setItems(hotLineSiteDao.list(bo));
        result.setTotal(hotLineSiteDao.countList(bo));
		return result;
	}
	
	/**
	 * 热门线路站点详情
	 * @param hotLineSiteId
	 * @return
	 * @throws DzcxException
	 */
	public Object detail(Long hotLineSiteId) throws DzcxException {
		Object result = hotLineSiteDao.detail(hotLineSiteId);
		if (result == null) {
			throw new DzcxException(ExceptionCode.数据不存在);
		}
		return result;
	}
	
	

}
